package me.zhengjie.minbearwcs.dao.config.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.config.inf.WcsParamConfigDao;
import me.zhengjie.minbearwcs.entity.Mapper.config.WcsParamConfigMapper;
import me.zhengjie.minbearwcs.entity.PO.config.WcsParamConfig;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class WcsParamConfigImpl implements WcsParamConfigDao {

    private final WcsParamConfigMapper mapper;

    @Override
    public WcsParamConfig selectByKey(String key) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(WcsParamConfig::getConfigKey,key)
                .one();
    }

    @Override
    public boolean insert(WcsParamConfig wcsParamConfig) {
        return mapper.insert(wcsParamConfig) == 1;
    }

    @Override
    public boolean updateByConfigKey(String configKey, String paramConfig) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(WcsParamConfig::getConfigKey,configKey)
                .set(WcsParamConfig::getConfigValue,paramConfig)
                .update();
    }
}
